﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace WindowsFormsApplication2.CLASS
{
    public class XT
    {
        #region " & PropertyS & "
        private string _XTolologchId;
        public string XTolologchId
        {
            get { return _XTolologchId; }
            set { _XTolologchId = value; }
        }
        private string _XTolologchName;
        public string XTolologchName
        {
            get { return _XTolologchName; }
            set { _XTolologchName = value; }
        }
        private string _XTolologchUName;
        public string XTolologchUName
        {
            get { return _XTolologchUName; }
            set { _XTolologchUName = value; }
        }
        private string _XTolologchAddress;
        public string XTolologchAddress
        {
            get { return _XTolologchAddress; }
            set { _XTolologchAddress = value; }
        }
        private string _XTolologchPhone;
        public string XTolologchPhone
        {
            get { return _XTolologchPhone; }
            set { _XTolologchPhone = value; }
        }
        private string _XTolologchPass;
        public string XTolologchPass
        {
            get { return _XTolologchPass; }
            set { _XTolologchPass = value; }
        }
        #endregion
        public XT()
        {
            //butsets

        }
        public XT(string _XTolologchId, string _XTolologchName, string _XTolologchUName, string _XTolologchAddress, string _XTolologchPhone, string _XTolologchPass)
        {
            this.XTolologchId = _XTolologchId;
            this.XTolologchName = _XTolologchName;
            this.XTolologchUName = _XTolologchUName;
            this.XTolologchAddress = _XTolologchAddress;
            this.XTolologchPhone = _XTolologchPhone;
            this.XTolologchPass = _XTolologchPass;
        }
        public static XT getbyRec(string _byXTolologchId)
        {
            XT x = new XT();

            string qry1 = string.Format("select *from  XTolologch where XTolologchId=('{0}')", _byXTolologchId);
            DataTable table = DBTools.selecQryTmp(qry1);

            try
            {
                return new XT(table.Rows[0]["XTolologchId"].ToString(), table.Rows[0]["XTolologchName"].ToString(), table.Rows[0]["XTolologchUName"].ToString(), table.Rows[0]["XTolologchAddress"].ToString(), table.Rows[0]["XTolologchPhone"].ToString(), table.Rows[0]["XTolologchPass"].ToString());


            }
            catch (Exception e)
            {
                //MsgBox(ex.Message, MsgBoxStyle.OkCancel, "account->getAccountByRecID")'
                MessageBox.Show(string.Format("{0} Exception caught.", e));

                return null;
            }



        }
        public static bool AddFunction(string _XTolologchId, string _XTolologchName, string _XTolologchUName, string _XTolologchAddress, string _XTolologchPhone, string _XTolologchPass)
        {

           // DBTools._Conn.Open();
            DBTools._Comm.CommandText = "StoredProcedureXTolologch";
            DBTools._Comm.CommandType = CommandType.StoredProcedure;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchId", SqlDbType.NVarChar, 8)).Value = _XTolologchId;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchName", SqlDbType.NVarChar, 25)).Value = _XTolologchName;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchUName", SqlDbType.NVarChar, 25)).Value = _XTolologchUName;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchAddress", SqlDbType.NVarChar, 25)).Value = _XTolologchAddress;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchPhone", SqlDbType.NVarChar, 10)).Value = _XTolologchPhone;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchPass", SqlDbType.NVarChar, 16)).Value = _XTolologchPass;


            DBTools._Comm.Parameters.Add(new SqlParameter("@Otype", SqlDbType.NVarChar, 4)).Value = "ADD";
            SqlParameter prm = new SqlParameter("@returnValue", SqlDbType.TinyInt);
            DBTools._Comm.Parameters.Add(prm);
            prm.Direction = ParameterDirection.Output;
            string isOk;
            try
            {
                int rowcount = DBTools._Comm.ExecuteNonQuery();
                DBTools._Comm.Parameters.Clear();
                isOk = Convert.ToString(prm.Value);



                if (isOk == "1")
                {
                    return true;

                }
                else
                {
                    return false;

                }
            }


            catch (SqlException ex)
            {
                DBTools._Comm.Parameters.Clear();
                MessageBox.Show(ex.Message);


            }

            return false;
        }
        public static bool EditFunction(string _byXTolologchId, string _byXTolologchName, string _byXTolologchUName, string _byXTolologchAddress, string _byXTolologchPhone, string _byXTolologchPass)
        {


           // DBTools._Conn.Open();
            DBTools._Comm.CommandText = "StoredProcedureXTolologch";
            DBTools._Comm.CommandType = CommandType.StoredProcedure;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchId", SqlDbType.NVarChar, 8)).Value = _byXTolologchId;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchName", SqlDbType.NVarChar, 25)).Value = _byXTolologchName;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchUName", SqlDbType.NVarChar, 25)).Value = _byXTolologchUName;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchAddress", SqlDbType.NVarChar, 25)).Value = _byXTolologchAddress;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchPhone", SqlDbType.NVarChar, 10)).Value = _byXTolologchPhone;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchPass", SqlDbType.NVarChar, 16)).Value = _byXTolologchPass;
            DBTools._Comm.Parameters.Add(new SqlParameter("@Otype", SqlDbType.NVarChar, 4)).Value = "EDIT";
            SqlParameter prm = new SqlParameter("@returnValue", SqlDbType.TinyInt);
            DBTools._Comm.Parameters.Add(prm);
            prm.Direction = ParameterDirection.Output;
            string isOk;
            try
            {
                int rowcount = DBTools._Comm.ExecuteNonQuery();
                DBTools._Comm.Parameters.Clear();
                isOk = Convert.ToString(prm.Value);



                if (isOk == "1")
                {
                    return true;

                }
                else
                {
                    return false;

                }
            }


            catch (SqlException ex)
            {
                DBTools._Comm.Parameters.Clear();
                MessageBox.Show(ex.Message);


            }

            return false;




        }

        public static bool DelFunction(string _byXTolologchId)
        {


            DBTools._Comm.CommandText = "StoredProcedureXTolologch";
            DBTools._Comm.CommandType = CommandType.StoredProcedure;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchId", SqlDbType.NVarChar, 8)).Value = _byXTolologchId;
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchName", SqlDbType.NVarChar, 25)).Value = ""; 
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchUName", SqlDbType.NVarChar, 25)).Value = "";
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchAddress", SqlDbType.NVarChar, 25)).Value = "";
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchPhone", SqlDbType.NVarChar, 10)).Value = "";
            DBTools._Comm.Parameters.Add(new SqlParameter("@XTolologchPass", SqlDbType.NVarChar, 16)).Value = "";

            DBTools._Comm.Parameters.Add(new SqlParameter("@Otype", SqlDbType.NVarChar, 4)).Value = "DEL";
            SqlParameter prm = new SqlParameter("@returnValue", SqlDbType.TinyInt);
            DBTools._Comm.Parameters.Add(prm);
            prm.Direction = ParameterDirection.Output;
            string isOk;
            try
            {
                int rowcount = DBTools._Comm.ExecuteNonQuery();
                DBTools._Comm.Parameters.Clear();
                isOk = Convert.ToString(prm.Value);



                if (isOk == "1")
                {
                    return true;

                }
                else
                {
                    return false;

                }
            }


            catch (SqlException ex)
            {
                DBTools._Comm.Parameters.Clear();
                MessageBox.Show(ex.Message);


            }

            return false;

       



        }
    }
}